package com.ksyun.campus.client;


import com.ksyun.campus.client.common.context.ServerContext;
import com.ksyun.campus.client.domain.ClusterInfo;
import com.ksyun.campus.client.domain.StatInfo;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;


import java.util.List;


public class testEFileSystem {
    private EFileSystem eFileSystem = new EFileSystem("fbsFileSystem");

    /**
     * 在每次测试前启动Zookeeper 将获取的集群信息存入ThreadLocal
     * @throws Exception
     */
    @Before
    public void createZooConnect() throws Exception {
        eFileSystem.clientToMetaService.zkUtil.postCons();
        System.out.println("测试Before:从ThreadLocal中获取metaServerList: "+ServerContext.getMetaServerList());
    }


    @Test
    public void testClusterInfo(){
        ClusterInfo clusterInfo = eFileSystem.getClusterInfo();
        System.out.println("获取到的集群信息："+clusterInfo);
    }

    @Test
    public void testDelete(){
        boolean isdelete = eFileSystem.delete("替换为测试的文件路径");
        System.out.println("是否删除成功: "+isdelete);
    }
    @Test
    public void testStats(){
        StatInfo fileStatInfo = eFileSystem.getFileStats("替换为测试的文件路径");
        System.out.println("该文件元数据内容: "+fileStatInfo);
    }

    @Test
    public void testMkdir(){
        boolean ismkdir = eFileSystem.mkdir("替换为测试的文件路径");
        System.out.println("是否创建成功: "+ismkdir);
    }
    @Test
    public void testListDir(){
        List<StatInfo> statInfoList = eFileSystem.listFileStats("替换为测试的文件路径");
        System.out.println("该目录下文件元数据内容: "+statInfoList);
    }

    /**
     * 关闭zookeeper连接
     */
    @After
    public void closeZK(){
        eFileSystem.clientToMetaService.zkUtil.close();
        System.out.println("测试: 关闭与zooKeeper的连接");
    }

}
